;
(function (window) {
    var cj = window.createjs;
    var basePath = window.HOST + 'img/game/' + (document.querySelector('#content').clientWidth > 360 ? 2 : 2) + 'x/';
    var random = function (min, max) {
        if (max == null) {
            max = min;
            min = 0;
        }
        return min + Math.floor(Math.random() * (max - min + 1));
    };
    var _App = {};
    _App.config = {
        speed: {
            dogGap: 800, //600ms 出1只狗
            shutGap: 500, //500ms 攻击一次
            dogRun: '3500-6000', // dog跑到底的时间，范围内随机
            cart: '2000', //购物车左右移动速度
            cartGap: '5000', //购物车每3000ms秒出现一次
            bigCartClear: '800' //全屏清狗动画持续时长
        },
        dogs: [
            {random: 50, score: 1},
            {random: 20, score: 10},
            {random: 30, score: 5}
        ]
    }


    var chengHao = 'img/2x/chenghao{i}.png';
    var str = '鲁有脚,耶律齐,杨过,乔峰,黄蓉,洪七公'.split(',');
    var defenDom = document.querySelector('.defen');
    var setDeFen = function (num) {
        var x = document.querySelector('.over').clientHeight * 0.425;
        defenDom.style.cssText = 'margin-top:' + x + 'px';
        var i = 0;
        if (num < 50) {
            i = 1;
        } else if (num < 100) {
            i = 2;
        } else if (num < 150) {
            i = 3;
        } else if (num < 200) {
            i = 4;
        } else if (num < 300) {
            i = 5;
        } else {
            i = 6;
        }
        var len = Math.max(num.toString().split('').length, 4);
        var w = defenDom.clientWidth / len;

        //console.log()

        var defen = num.toString().split('').map(function (val) {
            return '<img src="img/2x/defen.png" style="width:' + w + 'px;top:-' + val * 149 * (w / 90) + 'px" />';
            //return '<i class="n' + val + '"></i>';
        }).join('');

        //alert(x)

        /*
         * 400分（含）以上获得称号 洪七公 6
         300分（不含）-200获得称号 黄蓉 5
         200分（不含）-150获得称号 乔峰 4
         150（不含）-100分获得称号 杨过 3
         100（不含）-50分获得称号 耶律齐 2
         50（不含） 分以内获得称号 鲁有脚 1
         */

        defenDom.innerHTML = '<span class="num" style="height:' + w + 'px">' + defen + '</span><img style="margin-top:' + w * 0.7 + 'px" class="chenghao" src="' + chengHao.replace('{i}', i) + '" alt="你打狗时候的样子跟' + str[i - 1] + '一样有型" />';
    }
    //document.querySelector('.over').style.display = 'block'
    //setDeFen(1234987);
    //资源配置
    _App.manifest = 'lawn.jpg,tree.png,role.png,dogs1.png,dogs2.png,dogs3.png,sorce.png,stick.png,bomb.png,cart.png,cartAnime.png'.split(',').map(function (val, key) {
        return {
            src: basePath + val, id: val.substr(0, val.indexOf('.'))
        };
    });
    _App.manifest.push({
        src: window.HOST + 'img/2x/defen.png',
        id: 'defen'
    })
    var stage, c_w, c_h, loader, role, character, sticksList = [], dogList = [], x, y, res, scaleX, scaleY;
    var allowRun = false;
    _App.bind = function () {
        allowRun = true;
        if (res) {
            _App.playLoading(function () {
                _App.run();
            });
        }
    }
    _App.init = function () {
        var canvas = document.querySelector('canvas');
        var content = document.querySelector('#content');
        canvas.width = content.clientWidth;
        canvas.height = content.clientHeight;
        stage = new cj.Stage(canvas);
        stage.interactionEnabled = false;

        cj.Ticker.timingMode = cj.Ticker.RAF;//设置循环方法，可以是requestAnimationFrame或者是setTimeout
        cj.Ticker.setFPS(30);//舞台帧率控制
        cj.Touch.enable(stage);
        //console.log(stage)
        c_w = stage.canvas.width;
        c_h = stage.canvas.height;

        loader = new cj.LoadQueue(false);

        loader.addEventListener('complete', function () {        //当图片素材load完后执行该方法
            res = {};
            loader.getItems(true).forEach(function (val, key) {
                res[val.item.id] = val.result;
            });
            scaleX = c_w / res.lawn.width;
            scaleY = c_h / res.lawn.height;

            stage.addChild(new cj.Bitmap(res.lawn).setTransform(0, 0, scaleX, scaleY));

            var daoJuCharacter = new cj.Container();
            stage.addChild(daoJuCharacter);

            var tree = new cj.Bitmap(res.tree).setTransform(0, 0, scaleX, scaleY);
            tree.alpha = 0.9;
            stage.addChild(tree);


            y = 900 / 1136 * c_h;
            x = (c_w / 2 - res.role.width * scaleX / 2);
            var dogCharacter = new cj.Container();
            stage.addChild(dogCharacter);

            var roleSpriteSheet = new cj.SpriteSheet({
                images: [res.role],
                frames: {'height': res.role.height / 4, 'width': res.role.width},
                animations: {
                    stand: {
                        frames: [0, 1],
                        next: 'stand',
                        speed: 0.7
                    },
                    run: {
                        frames: [2, 3],
                        next: 'run',
                        speed: 1
                    },
                    shut: {
                        frames: [3, 4],
                        next: 'run',
                        speed: 0.7
                    }
                },
                framerate: 6
            });

            var roleStand = 'stand';
            role = new cj.Sprite(roleSpriteSheet, roleStand).setTransform(0, 0, scaleX, scaleX);
            //创建阴影
            var roleShadow = new cj.Shape();
            var shadow = {
                w: res.role.width * scaleX * 0.7,
                h: res.role.height / 4 * scaleX * 0.2
            }
            shadow.x = shadow.w * 0.08;
            shadow.y = res.role.height / 4 * scaleX - shadow.h / 1.3;
            roleShadow.graphics.beginFill("black")
                    .drawEllipse(shadow.x, shadow.y, shadow.w, shadow.h); //椭圆的最左端位置x,y;长度,高度

            roleShadow.alpha = 0.4;
            character = new cj.Container();
            character.addChild(roleShadow, role);
            //character.regX = -x//c_w;
            //character.regY = 0//res.role.height * scaleX;
            character.x = x;
            character.y = y;
            character.w = 158 * scaleX;
            character.h = 200 * scaleX;
            character.tickEnabled = true;
            character.stage = stage;
            stage.addChild(character);
            //pressup
            character.on('pressup', function (e) {
                roleStand = 'stop';
                role.gotoAndPlay('stand');
            });
            var leftFix, curX;
            character.on('pressmove', function (e) {

                if (roleStand != 'run') {
                    leftFix = character.x;
                    curX = e.stageX;
                    roleStand = 'run';
                    role.gotoAndPlay('run');
                }
                character.x = Math.max(0, e.stageX - curX + leftFix);
            });


            /*
             _App.bomb.setDubbleTimer = false;
             _App.bomb.setDubble = function(){
             if(_App.bomb.setDubbleTimer){
             var bomb2 = bomb.clone();
             bomb2.x
             stage.addChild(bomb2);
             _App.bombList.push(bomb2);
             }
             }*/

            var stickObj = {
                dubbleTimer: false,
                setDubble: function () {
                    stickObj.dubbleTimer && clearTimeout(stickObj.dubbleTimer);
                    stickObj.dubbleTimer = setTimeout(function () {
                        stickObj.dubbleTimer = false;

                    }, 10000);

                },
                create: function () {
                    var stick = new cj.Bitmap(res.stick).setTransform(0, 0, scaleX, scaleX);

                    stick.x = character.x + res.role.width * 0.755 * scaleX / 2;
                    stick.y = character.y;
                    stick.w = res.stick.width * scaleX;
                    stick.h = res.stick.height * scaleX;
                    if (stickObj.dubbleTimer) {
                        stick.x = character.x
                    }
                    sticksList.push(stick);
                    stick._remove = function () {
                        sticksList.splice([sticksList.indexOf(stick)], 1);
                        stage.removeChild(stick);
                    }
                    stage.addChild(stick);
                    TweenMax.to(stick, 1, {y: -stick.h, onComplete: function () {
                            sticksList.splice([sticksList.indexOf(stick)], 1);
                            stage.removeChild(stick);
                        }});
                    !_App.stop && setTimeout(function () {
                        stickObj.create();
                    }, _App.config.speed.shutGap);

                    if (stickObj.dubbleTimer) {
                        var stick2 = stick.clone();
                        stick2.x = character.x + res.role.width * 0.755 * scaleX - stick.w;
                        stick2.y = character.y;
                        stick2.w = stick.w;
                        stick2.h = stick.h;
                        sticksList.push(stick2);
                        stick2._remove = function () {
                            sticksList.splice([sticksList.indexOf(stick2)], 1);
                            ;
                            stage.removeChild(stick2);
                        }
                        stage.addChild(stick2);
                        TweenMax.to(stick2, 1, {y: -stick2.h, onComplete: function () {
                                sticksList.splice([sticksList.indexOf(stick2)], 1);
                                stage.removeChild(stick2);
                            }});
                    }

                }
            }
            //发射
            _App.bombList = [];
            _App.bomb = function (dog, stick) {
                var bomb = new cj.Bitmap(res.bomb).setTransform((dog.x + dog.w) / 2, (dog.y + res.bomb.height * scaleX) / 2, scaleX, scaleX);
                bomb.x = dog.x;
                bomb.y = dog.y;
                stage.addChild(bomb);
                _App.bombList.push(bomb);
                TweenMax.to(bomb, 0.7, {alpha: 0, onComplete: function () {
                        _App.bombList.splice(_App.bombList.indexOf(bomb), 1);
                        stage.removeChild(bomb);
                    }});
                stick && stick._remove();
                //stick
            }
            var Dogs = {
                type: [
                    {random: 50, score: 1, blood: 1, shut: 1},
                    {random: 20, score: 10, blood: 2, shut: 2},
                    {random: 30, score: 5, blood: 1, shut: 2}
                ],
                sprites: [
                    {
                        images: [res.dogs1],
                        frames: {'height': Math.ceil(res.dogs1.height / 6), 'width': res.dogs1.width},
                        animations: {
                            run: {
                                frames: [0, 3],
                                next: 'run',
                                speed: 1
                            },
                            attach: {
                                frames: [4]
                            },
                            shut: {
                                frames: [5],
                                next: 'run',
                                speed: 1
                            }
                        },
                        framerate: 6
                    },
                    {
                        images: [res.dogs2],
                        frames: {'height': Math.floor(res.dogs2.height / 6), 'width': res.dogs2.width},
                        animations: {
                            run: {
                                frames: [0, 3],
                                next: 'run',
                                speed: 1
                            },
                            attach: {
                                frames: [4]
                            },
                            shut: {
                                frames: [5],
                                next: 'run',
                                speed: 1
                            }
                        },
                        framerate: 6
                    },
                    {
                        images: [res.dogs3],
                        frames: {'height': Math.ceil(res.dogs3.height / 6), 'width': res.dogs3.width},
                        animations: {
                            run: {
                                frames: [0, 3],
                                next: 'run',
                                speed: 1
                            },
                            attach: {
                                frames: [4]
                            },
                            shut: {
                                frames: [5],
                                next: 'run',
                                speed: 1
                            }
                        },
                        framerate: 6
                    }
                ],
                hint: [],
                spriteSheetsObjects: {},
                create: function () {
                    var rnd = random(1, 100); //1-100;
                    var dogType = 0;
                    if (rnd <= Dogs.type[0].random) {
                        dogType = rnd < Dogs.type[1].random ? 1 : 2;
                    }
//console.log(dogType,Dogs.SpriteSheets[dogType])
                    if (!Dogs.spriteSheetsObjects[dogType]) {
                        Dogs.spriteSheetsObjects[dogType] = new cj.SpriteSheet(Dogs.sprites[dogType]);
                    }

                    var dogSprite = new cj.Sprite(Dogs.spriteSheetsObjects[dogType], 'run').setTransform(0, 0, scaleX, scaleX);
                    //console.log(typeof dogSprite,dogSprite.getBounds())
                    //dogSprite.scaleX = scaleX / 1.2;
                    //dogSprite.scaleY = scaleX / 1.2;
                    dogSprite.dogType = dogType;



                    var dogRes = res['dogs' + (dogType + 1)];

                    dogSprite._score = Dogs.type[dogType].score;
                    dogSprite._blood = Dogs.type[dogType].blood;
                    dogSprite.y = 0;
                    dogSprite.x = random(0, c_w - dogRes.width * scaleX);
                    dogSprite.w = dogRes.width * scaleX;
                    dogSprite.h = dogRes.height / 6 * scaleX;
                    dogSprite._shut = Dogs.type[dogType].shut;

                    //var dogShadow = new cj.Shape();
                    //dogShadow.graphics.beginFill("black")
                    //.drawEllipse(dogSprite.x,  dogSprite.h, dogSprite.w, 40 * scaleX); //椭圆的最左端位置x,y;长度,高度


                    //dogShadow.alpha = 0.4;
                    //dogSprite.dogShadow = dogShadow;
                    //dogCharacter.addChild(dogShadow);

                    dogCharacter.addChild(dogSprite);
                    //dogSprite.aph
                    dogSprite.on('removed', function () {
                        //绑定狗被移除
                    });
                    dogSprite._remove = function () {
                        dogList.splice([dogList.indexOf(dogSprite)], 1);
                        dogCharacter.removeChild(dogSprite);
                        //dogCharacter.removeChild(dogSprite.dogShadow);
                    }

                    dogList.push(dogSprite);

                    var speed = random.apply(null, _App.config.speed.dogRun.split('-').map(function (v) {
                        return  v - 0;
                    }));
                    speed -= _App.gameTime;
//_App.config.speed.dogGap = 3000;
                    var dogSpeed = speed/1000;
                    if(dogType == 1){
                        dogSpeed = dogSpeed / 1.5;
                    }
                    TweenMax.to(dogSprite, dogSpeed, {y: c_h, onComplete: function () {


                            dogList.splice([dogList.indexOf(dogSprite)], 1);

                            dogCharacter.removeChild(dogSprite);
                            //dogCharacter.removeChild(dogSprite.dogShadow);
                        }});
                    !_App.stop && setTimeout(function () {
                        Dogs.create();
                    }, _App.config.speed.dogGap);
                }
            };
            var spriteSheetFrames = [
                // x, y, width, height, imageIndex, regX, regY
                [0, 0, 100, 97, 0, 0, 0],
                [100, 0, 100, 97, 0, 0, 0],
                [200, 0, 100, 97, 0, 0, 0],
                [0, 97, 100, 97, 0, 0, 0],
                [100, 97, 100, 97, 0, 0, 0],
                [200, 97, 100, 97, 0, 0, 0],
                [0, 194, 100, 97, 0, 0, 0],
                [100, 194, 100, 97, 0, 0, 0],
                [300, 0, 165, 174, 0, 0, 0] //大购物车
            ];
            var daojuSprite = new cj.SpriteSheet({
                images: [res.cart],
                frames: spriteSheetFrames
            });
            _App.daoJu = {
                timer: false,
                list: [],
                createBigCart: function (x, y) {
                    //console.log(x, y)
                    var bigCart = new cj.Sprite(daojuSprite, 8).setTransform(0, 0, scaleX, scaleX);
                    bigCart.x = x;
                    bigCart.y = y;
                    bigCart.w = 165 * scaleX;
                    bigCart.h = 174 * scaleX;
                    bigCart.tickEnabled = false;
                    _App.daoJu.list.push(bigCart);
                    daoJuCharacter.addChild(bigCart);


                    bigCart._remove = function () {
                        TweenMax.killTweensOf(bigCart);
                        _App.daoJu.list.splice(_App.daoJu.list.indexOf(bigCart), 1);
                        daoJuCharacter.removeChild(bigCart);

                    }
                    bigCart._shut = function () {
                        stickObj.setDubble();
                    }
                    TweenMax.to(bigCart, 2, {x: bigCart.x == 0 ? c_w - 100 * c_w / 640 : 0, onComplete: function () {
                            bigCart._remove();
                        }});


                    bigCart._shut = function () {
                        var cartAnime = new Image();
                        cartAnime.src = res.cartAnime.src;
                        document.body.appendChild(cartAnime);
                        var w = res.cartAnime.width * scaleX;
                        cartAnime.style.cssText = 'position:absolute;bottom:0;width:' + w + 'px;left:50%;margin-left:-' + w / 2 + 'px';
                        _App.daoJu.list.splice(_App.daoJu.list.indexOf(bigCart), 1);
                        bigCart._remove();
                        _App.bigCartShut = true;
                        setTimeout(function () {
                            _App.bigCartShut = false;
                            document.body.removeChild(cartAnime);
                        }, _App.config.speed.bigCartClear);

                    }
                    /*bigCart.on('pressup', function () {
                     });*/

                },
                create: function () {
                    _App.daoJu.timer = setInterval(function () {
                        if (_App.daoJu.list.length > 4) {
                            return
                        }
                        if (_App.stop) {
                            clearInterval(_App.daoJu.timer)
                            return;
                        }
                        //createBigCart
                        var cartType = random(0, 8);// 0-7 普通购物车，8全屏清狗
                        var _y = random(2, 14);
                        var moveTo = c_w - 100 * c_w / 640;
                        var _x = [0, moveTo][random(0, 1)];
                        if (cartType == 8) {
                            _App.daoJu.createBigCart(_x, _y);
                        } else {
                            var cart = new cj.Sprite(daojuSprite, random(0, 7)).setTransform(0, 0, scaleX, scaleX);
                            cart.x = _x;//
                            cart.y = _y * 50 * c_w / 640;
                            cart.w = spriteSheetFrames[0][2] * scaleX;
                            cart.h = spriteSheetFrames[0][2] * scaleX;


                            //console.log(cart.x,cart.y)
                            cart.tickEnabled = false;
                            daoJuCharacter.addChild(cart);
                            _App.daoJu.list.push(cart);
                            cart._remove = function () {
                                TweenMax.killTweensOf(cart);
                                _App.daoJu.list.splice(_App.daoJu.list.indexOf(cart), 1);
                                daoJuCharacter.removeChild(cart);

                            }
                            cart._shut = function () {
                                stickObj.setDubble();
                                cart._remove();
                            }
                            TweenMax.to(cart, _App.config.speed.cart / 1000, {x: cart.x == 0 ? moveTo : 0, onComplete: function () {
                                    cart._remove();
                                }});
                        }

                    }, _App.config.speed.cartGap);
                },
                stop: function () {
                    clearInterval(_App.daoJu.timer);
                    _App.daoJu.list.forEach(function (cart) {
                        _App.daoJu.list.splice(_App.daoJu.list.indexOf(cart), 1);
                        daoJuCharacter.removeChild(cart);
                    })
                }
            }

            var gameTimeAdd = false;
            var daoJuTimer = false;
            _App.run = function () {
                _App.gameTime = 0;
                gameTimeAdd && clearInterval(gameTimeAdd);
                gameTimeAdd = setInterval(function () {
                    _App.gameTime++;
                    if (_App.gameTime == 1500) {
                        clearInterval(gameTimeAdd);
                        gameTimeAdd = false;
                    }
                }, 300);


                _App.daoJu.create();
                stickObj.create();
                Dogs.create();
                cj.Ticker.addEventListener('tick', _App.handleTick);//绑定舞台每一帧的逻辑发生函数
            }
            if (allowRun) {
                _App.playLoading(function () {
                    _App.run();
                });
            }
            stage.update();
        });
        loader.loadManifest(_App.manifest);

        //drawLoading();
    };
    var blood = document.querySelector('.blood');
    _App.blood = function (n) {
        var nowBlood = 3;
        if (blood.className.indexOf('blood-one') >= 0) {
            nowBlood = 1;
        } else if (blood.className.indexOf('blood-two') >= 0) {
            nowBlood = 2;
        } else if (blood.className.indexOf('blood-zero') >= 0) {
            nowBlood = 0;
        }
        nowBlood -= n;

        if (nowBlood == 2) {
            blood.className = 'blood blood-two';
        } else if (nowBlood == 1) {
            blood.className = 'blood blood-one';
        } else {
            blood.className = 'blood blood-zero';
            _App.gameOver();
        }
    }
    var source = document.querySelector('.source span');
    var sourceAnim = document.querySelector('.source p');
    var mySource = 0;
    _App.score = function (n) {
        //if (n == 10) {
        //_App.daoJu.createBigCart(x, y)
        //}
        try {
            TweenMax.killTweensOf(sourceAnim);
        } catch (ex) {
        }
        sourceAnim.innerHTML = '+' + n;
        mySource += n;
        sourceAnim.style.cssText = '';
        var left = n >= 10 ? '30%' : '50%';
        TweenMax.to(sourceAnim, 1, {css: {opacity: 0, top: 0, fontSize: 20, left: left}, onComplete: function () {

            }});
        var i = parseInt(source.innerHTML, 10);
        n += i;
        source.innerHTML = n;


    }
    _App.gameOver = function () {
        _App.stop = true;
        _App.daoJu.stop();
        document.querySelector('.game').style.display = 'none';
        document.querySelector('.over').style.display = 'block';
        setDeFen(mySource);
        setTimeout(function () {
            character.x = x;
            dogList.forEach(function (dog, k) {
                dog && dog._remove && dog._remove();
            });
            sticksList.forEach(function (stick, i) {
                stick && stick._remove && stick._remove();
            });
            _App.bombList.forEach(function (bomb, i) {
                stage.removeChild(bomb);
                _App.bombList.splice(_App.bombList.indexOf(bomb), 1);
            });
            cj.Ticker.removeEventListener('tick', _App.handleTick);
            role.gotoAndPlay('stand');
            stage.update();
        }, 1000);
    };
    _App.playLoading = function (callback) {

        document.querySelector('.loading') && (document.querySelector('.loading').style.display = 'none');
        var load = document.querySelector('reload-loading');
        if (!load) {
            var load = document.createElement('div');
            load.className = 'reload-loading';
            document.body.appendChild(load);
        } else {
            load.style.display = 'block';
        }
        var i = 4;
        var run = function () {
            i--;
            load.innerHTML = '<span style="font-size:200px;line-height:' + c_h + 'px">' + i + '</span>';
            var span = load.querySelector('span');
            setTimeout(function () {
                span.style.cssText = 'font-size:0px;opacity:0;line-height:' + c_h + 'px';
                if (i > 1) {
                    setTimeout(function () {
                        run();
                    }, 700);
                } else {
                    setTimeout(function () {
                        load.style.display = 'none';
                        callback();
                    }, 700);

                }
            }, 100);
        }
        run();
    }
    _App.replay = function () {
        document.querySelector('.game').style.display = 'block';
        document.querySelector('.over').style.display = 'none';
        document.querySelector('canvas').width = document.querySelector('canvas').width
        mySource = 0;
        source.innerHTML = 0;
        blood.className = 'blood';
        _App.stop = false;
        _App.init();
        /*
         _App.playLoading(function () {
         _App.run();
         });*/
        //replay
    }
    var checkTimer = false;
    _App.checkTap = function () {
        checkTimer = clearTimeout(checkTimer);
        var roleMidd = character.x + 160 * scaleX / 2;
        var roleWidth = character.w * 0.8;

        //var dogForEach = fun
        if (_App.bigCartShut) {
            var _score = 0;
            dogList.length && dogList.forEach(function (dog, k) {
                _score += dog._score;
                dog._stop = true;
                TweenMax.killTweensOf(dog);
                dog._remove();
                _App.bomb(dog);
            });
            _score && _App.score(_score);
        }
        dogList.forEach(function (dog, k) {
            if (dog) {
                var dogMidd = dog.x + dog.w / 2;
                var dogFix = dog.w * 0.08;
                if (!dog._stop && dog.y + dog.h * 0.5 >= character.y &&
                        Math.abs(roleMidd - dogMidd) < roleWidth) {
                    dog._stop = true;
                    TweenMax.killTweensOf(dog);
                    _App.blood(dog._blood);
                    dog.gotoAndPlay('attach');
                    TweenMax.to(dog, 0.2, {alpha: 0, onComplete: function () {
                            dog._remove();
                        }});
                }
            }
        });
        sticksList.forEach(function (stick, i) {
            if (stick && !stick._stop) {
                var stickX = stick.x + res.stick.width * scaleX / 2;
                dogList.forEach(function (dog, k) {
                    if (dog) {
                        var dogFix = dog.w * 0.08;
                        if (_App.bigCartShut || (!dog._stop && dog.y + dog.h >= stick.y &&
                                dog.x + dogFix <= stickX && dog.x + dog.w - dogFix >= stickX)) {
                            dog._shut--;
                            if (dog._shut == 0) {
                                _App.score(dog._score, dog.x, dog.y);
                                dog._stop = true;
                                TweenMax.killTweensOf(dog);
                                dog._remove();
                                TweenMax.killTweensOf(stick);
                                stick._stop = true;
                                _App.bomb(dog, stick);
                            }else{
                                dog.gotoAndPlay('shut');
                                stick._stop = true;
                                stage.removeChild(stick)
                            }
                        }
                    }
                });
                _App.daoJu.list.forEach(function (daoju, k) {
                    if (daoju) {
                        var daojuFix = daoju.w * 0.08;
                        var daojuMidd = daoju.x + daoju.w / 2;
                        if (!daoju._stop && daoju.y + daoju.h >= stick.y &&
                                daoju.x + daojuFix <= stickX && daoju.x + daoju.w - daojuFix >= stickX) {
                            daoju._stop = true;
                            TweenMax.killTweensOf(daoju);
                            daoju._shut();
                            TweenMax.killTweensOf(stick);
                            stick._stop = true;
                            sticksList.splice(sticksList.indexOf(stick), 1);
                            stage.removeChild(stick);
                        }
                    }
                });
            }
        });

    }
    _App.handleTick = function (event) {
        stage.update(event);
        _App.checkTap();
        //dogList
        //console.log(role.update)
        //role.update();
    }

    window.App = {
        init: _App.init,
        bind: _App.bind,
        replay: _App.replay,
        getScore: function () {
            return mySource;
        }
    };
})(window);